<?php
/**
 * 用户组
 *
 * @version        2015年7月12日Z by 海东青
 * @package        DuomiCms.Administrator
 * @copyright      Copyright (c) 2015, SamFea, Inc.
 * @link           http://www.duomicms.net
 */
require_once(dirname(__FILE__)."/config.php");
CheckPurview();
if(empty($action))
{
	$action = '';
}

if($action=='editsave')
{
	$gname = trim($gname);
	if(empty($gname)){
		ShowMsg("用户组名称没有填写","-1");
		exit();
	}
	$gtype = implode(',',$gtype);
	$g_auth = implode(',',$g_auth);
	$g_upgrade = intval($g_upgrade);
	$g_authvalue = intval($g_authvalue);
	$gname = cn_substrR($gname,20);
	$g_day = intval($g_day);
	$query = "update `{$cfg_dbprefix}member_group` set gname='$gname',gtype='$gtype',g_auth='$g_auth',g_upgrade='$g_upgrade',g_authvalue='$g_authvalue',g_day ='$g_day' where gid='$id'";
	if($dsql->ExecuteNoneQuery($query))
	{
		ShowMsg("更新成功！","admin_members_group.php");
	}
	exit();
}
elseif($action=='addsave')
{
	$gname = trim($gname);
	if(empty($gname)){
		ShowMsg("用户组名称没有填写","-1");
		exit();
	}
	$row = $dsql->GetOne("Select gid From {$cfg_dbprefix}member_group where gname='$gname'");
	if(is_array($row))
	{
		ShowMsg("已经存在同名的用户组！","-1");
		exit();
	}
	$gtype = implode(',',$gtype);
	$g_auth = implode(',',$g_auth);
	$g_upgrade = intval($g_upgrade);
	$g_authvalue = intval($g_authvalue);
	$g_day = intval($g_day);
	$gname = cn_substrR($gname,20);
	$query = "INSERT INTO `{$cfg_dbprefix}member_group`(`gname`,`gtype`,`g_auth`,`g_upgrade`,`g_authvalue`, `g_day`) VALUES ('$gname','$gtype','$g_auth','$g_upgrade','$g_authvalue','$g_day');";
	if($dsql->ExecuteNoneQuery($query))
	{
		ShowMsg("成功增加一个用户组！","admin_members_group.php");
	}
	exit();
}
elseif($action=='edit')
{
	$row = $dsql->GetOne("Select * From `{$cfg_dbprefix}member_group` where gid=$id");
}
elseif($action=='del')
{
	if($dsql->ExecuteNoneQuery("Delete From `{$cfg_dbprefix}member_group` where gid='$id' "))
	{
		ShowMsg("删除成功！","admin_members_group.php");
	}
	exit;
}
elseif($action=='delall')
{
	if(empty($g_id))
	{
		ShowMsg("请选择需要删除的用户组","-1");
		exit();
	}
	foreach($g_id as $id){
		$dsql->ExecuteNoneQuery("Delete From `{$cfg_dbprefix}member_group` where gid='$id' ");
	}
	ShowMsg("删除成功！","admin_members_group.php");
	exit;
}

$dsql->SetQuery("select * from `{$cfg_dbprefix}member_group` order by g_upgrade asc");
$dsql->Execute('mytag_list');
$temp = 0;
while($row_group=$dsql->GetObject('mytag_list')){
	$rs=$dsql->getOne("SELECT * FROM {$cfg_dbprefix}arcrank WHERE rank=".$row_group->gid);
	if($rs){
		$dsql->ExecuteNoneQuery("UPDATE `dm_arcrank` SET `membername` = '{$row_group->gname}', `adminrank` = 5, `money` = '{$row_group->g_upgrade}', `scores` = '{$row_group->g_upgrade}', `purviews` = '' WHERE `rank` = '{$row_group->gid}'");
	}else{
		$dsql->ExecuteNoneQuery("INSERT INTO `{$cfg_dbprefix}arcrank` ( `rank`,`membername`,`adminrank`,`money`,`scores`, `purviews`) VALUES ({$row_group->gid}, '{$row_group->gname}', 5, {$row_group->g_upgrade}, {$row_group->g_upgrade}, '')");
	}
	

}





include(duomi_ADMIN.'/html/admin_members_group.htm');
exit();